/* common function sets                                                      */

/** convert progress date format to SQL yyyy-mm-dd format                    */
FUNCTION cDate2Str RETURN CHARACTER (idate AS DATE):
    DEFINE VARIABLE rdate AS CHARACTER FORMAT "x(10)".
    IF idate = ? THEN DO:
        ASSIGN rdate = "".
    END.
    ELSE DO:
        ASSIGN rdate = STRING(YEAR(idate),"9999") + "-" +
                       STRING(MONTH(idate),"99") + "-" +
                       STRING(DAY(idate),"99").
    END.
    RETURN rdate.
END FUNCTION.

/** get pt_desc1 pt_desc2 from idesc cut it to 40 character length           */
PROCEDURE getPtDesc:
DEFINE INPUT  PARAMETER iDesc  AS CHARACTER FORMAT "x(100)".
DEFINE OUTPUT PARAMETER oDesc1 AS CHARACTER FORMAT "x(40)".
DEFINE OUTPUT PARAMETER oDesc2 AS CHARACTER FORMAT "x(40)".

DEFINE VARIABLE vdesc LIKE iDesc.
DEFINE VARIABLE str   AS CHARACTER  NO-UNDO.

ASSIGN vDesc = iDesc.
str = SUBSTRING(vDesc, 39, 1, "RAW") + SUBSTRING(vDesc, 40, 1, "RAW").
IF INDEX(idesc, str) = 0 THEN DO:
   ASSIGN odesc1 = SUBSTRING(vDesc, 1, 39, "RAW")
          vdesc  = SUBSTRING(iDesc,LENGTH(SUBSTRING(iDesc,1,39,"RAW")) + 1,44).
END.
ELSE DO:
   ASSIGN odesc1 = SUBSTRING(vDesc, 1, 40, "RAW")
          vdesc  = SUBSTRING(iDesc,LENGTH(SUBSTRING(iDesc,1,40,"RAW")) + 1,44).
END.

str = SUBSTRING(vDesc, 39, 1, "RAW") + SUBSTRING(vDesc, 40, 1, "RAW").
IF INDEX(idesc, str) = 0 THEN
    odesc2 = SUBSTRING(vDesc, 1, 39, "RAW").
ELSE
    odesc2 = SUBSTRING(vDesc, 1, 40, "RAW").

END PROCEDURE.
